package com.client;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.DeckPanel;
import com.google.gwt.visualization.client.DataTable;
import com.google.gwt.visualization.client.LegendPosition;
import com.google.gwt.visualization.client.visualizations.AreaChart;
import com.google.gwt.visualization.client.visualizations.BarChart;
import com.google.gwt.visualization.client.visualizations.ColumnChart;
import com.google.gwt.visualization.client.visualizations.LineChart;
import com.google.gwt.visualization.client.visualizations.PieChart;
import com.google.gwt.visualization.client.visualizations.Table;

public class DPCharts extends DeckPanel {
	
	private AreaChart chArea = null;
	private BarChart chBar = null;
	private ColumnChart chColumn = null;
	private LineChart chLine = null;
	private PieChart chPie = null;
	private Table chTable = null;
	private AreaChart.Options opsArea = null;
	private BarChart.Options opsBar = null;
	private ColumnChart.Options opsColumn = null;
	private LineChart.Options opsLine = null;
	private PieChart.Options opsPie = null;
	private Table.Options opsTable = null;
	
	public AreaChart getAreaChart() {
		if(null == chArea) {
			chArea = new AreaChart();
			this.add(chArea);
		}
		return chArea;
	}
	
	public BarChart getBarChart() {
		if(null == chBar) {
			chBar = new BarChart();
			this.add(chBar);
		}
		return chBar;
	}
	
	public ColumnChart getColumnChart() {
		if(null == chColumn) {
			chColumn = new ColumnChart();
			this.add(chColumn);
		}
		return chColumn;
	}

	public LineChart getLineChart() {
		if(null == chLine) {
			chLine = new LineChart();
			this.add(chLine);
		}
		return chLine;
	}

	public PieChart getPieChart() {
		if(null == chPie) {
			chPie = new PieChart();
			this.add(chPie);
		}
		return chPie;
	}
	
	public Table getTableChart() {
		if(null == chTable) {
			chTable = new Table();
			this.add(chTable);
			double scale = 0.6;
			chTable.setPixelSize((int)(Window.getClientWidth()*scale), 
					(int)(Window.getClientHeight()*scale));
		}
		return chTable;
	}
	
	public AreaChart.Options getAreaOptions() {
		if(null == opsArea) {
			opsArea = AreaChart.Options.create();
			double scale = 0.6;
			opsArea.setSize((int)(Window.getClientWidth()*scale), 
					(int)(Window.getClientHeight()*scale));
			opsArea.setLegend(LegendPosition.BOTTOM);
		}
		return opsArea;		
	}
	
	public BarChart.Options getBarOptions() {
		if(null == opsBar) {
			opsBar = BarChart.Options.create();
			double scale = 0.6;
			opsBar.setSize((int)(Window.getClientWidth()*scale), 
					(int)(Window.getClientHeight()*scale));
			opsBar.setLegend(LegendPosition.BOTTOM);
		}
		return opsBar;
	}
	
	public ColumnChart.Options getColumnOptions() {
		if(null == opsColumn) {
			opsColumn = ColumnChart.Options.create();
			double scale = 0.6;
			opsColumn.setSize((int)(Window.getClientWidth()*scale), 
					(int)(Window.getClientHeight()*scale));
			opsColumn.setLegend(LegendPosition.BOTTOM);
		}
		return opsColumn;
	}
	
	public LineChart.Options getLineOptions() {
		if(null == opsLine) {
			opsLine = LineChart.Options.create();
			double scale = 0.6;
			opsLine.setSize((int)(Window.getClientWidth()*scale), 
					(int)(Window.getClientHeight()*scale));
			opsLine.setLegend(LegendPosition.BOTTOM);
		}
		return opsLine;
	}
	
	public PieChart.Options getPieOptions() {
		if(null == opsPie) {
			opsPie = PieChart.Options.create();
			double scale = 0.6;
			opsPie.setSize((int)(Window.getClientWidth()*scale), 
					(int)(Window.getClientHeight()*scale));
			opsPie.setLegend(LegendPosition.BOTTOM);
		}
		return opsPie;
	}
	
	public Table.Options getTableOptions() {
		if(null == opsTable) {
			opsTable = Table.Options.create();
		}
		return opsTable;
	}

	public void drawAreaChart(DataTable data) {
		this.getAreaChart().draw(data, this.getAreaOptions());
		this.showWidget(this.getWidgetIndex(this.getAreaChart()));
	}
	
	public void drawBarChart(DataTable data) {
		this.getBarChart().draw(data, this.getBarOptions());
		this.showWidget(this.getWidgetIndex(this.getBarChart()));
	}

	public void drawColumnChart(DataTable data) {
		this.getColumnChart().draw(data, this.getColumnOptions());
		this.showWidget(this.getWidgetIndex(this.getColumnChart()));
	}

	public void drawLineChart(DataTable data) {
		this.getLineChart().draw(data, this.getLineOptions());
		this.showWidget(this.getWidgetIndex(this.getLineChart()));
	}

	public void drawPieChart(DataTable data) {
		this.getPieChart().draw(data, this.getPieOptions());
		this.showWidget(this.getWidgetIndex(this.getPieChart()));
	}

	public void drawTableChart(DataTable data) {
		this.getTableChart().draw(data, this.getTableOptions());
		this.showWidget(this.getWidgetIndex(this.getTableChart()));
	}

}
